<template>
  <div id="contsainer"></div>
</template>
<script>
export default {
  data() {
    return {
      viewer: null
    }
  },
  mounted() {
    this.initCesium()
    this.addCesium3DTile(this.viewer)
  },
  methods: {
    initCesium() {
      this.viewer = new Cesium.Viewer('contsainer', {
        animation: false,
        baseLayerPicker: false,
        fullscreenButton: false,
        geocoder: false,
        homeButton: false,
        infoBox: false,
        sceneModePicker: false,
        navigationHelpButton: false,
        scene3DOnly: true,
        timeline: false,
        selectionIndicator: false, //是否显示选取指示器组件
        shouldAnimate: false, //自动播放动画控件
        shadows: true, //是否显示光照投射的阴影
        terrainShadows: Cesium.ShadowMode.RECEIVE_ONLY, //地质接收阴影
        sceneMode: Cesium.SceneMode.SCENE3D
      })
      this.viewer._cesiumWidget._creditContainer.style.display = 'none' //	去除版权信息
    },
    addCesium3DTile(viewer) {
      viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
        url: "http://localhost:8888/model/SampleData/Cesium3DTiles/Tilesets/Tileset/tileset.json",
        maximumScreenSpaceError: 20,             //最大屏幕空间误差
        maximumNumberOfLoadedTiles: 10000     //最大加载瓦片个数
      })).readyPromise.then(function (tileset) {

        let heightOffset = 1000;
        //包围球
        var boundingSphere = tileset.boundingSphere;
        var cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
        var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
        var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, heightOffset);
        var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
        let fromTranslation = Cesium.Matrix4.fromTranslation(translation);
        tileset.modelMatrix = fromTranslation;

        //获取到Cesium3DTile的根
        let cesium3dTile = tileset._root;
        //获取到自身的变换矩阵
        let computedMatrix = cesium3dTile.computedTransform;
        //获取到自身的本地变换矩阵
        let transformMatrix = cesium3dTile.transform;
        //获取到父级
        let parent = cesium3dTile.parent;
        //获取到子级
        let children = cesium3dTile.children;
        console.log(fromTranslation)
        console.log(computedMatrix)
        console.log(transformMatrix)
        console.log(parent)
        console.log(children)
        viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.0, -0.5, tileset.boundingSphere.radius * 2.0));
      })
    }
  }
}
</script>
<style scoped>
#contsainer {
  height: 100%;
  width: 100%;
  background-color: red;
}
</style>
